<template>
    <el-card>
        <el-form :inline="true">
            <el-form-item label="一级分类">
                <el-select style="width: 160px" v-model="categoryStore.c1Id" @change="handlerC1">
                    <el-option v-for="(item,index) in categoryStore.c1Arr" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="二级分类">
                <el-select style="width: 160px" v-model="categoryStore.c2Id" @change="handlerC2">
                    <el-option v-for="(item,index) in categoryStore.c2Arr" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="三级分类">
                <el-select style="width: 160px" v-model="categoryStore.c3Id">
                    <el-option v-for="(item,index) in categoryStore.c3Arr" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
    </el-card>
</template>

<script setup lang='ts'>
import {onMounted} from 'vue'
import useCategoryStore from '@/store/modules/category'
let categoryStore = useCategoryStore()
onMounted(()=>{
    getC1()
})
const getC1 = ()=>{
    //获取一级分类
    categoryStore.getC1()
}
//一级分类change事件
const handlerC1 = ()=>{
    categoryStore.c2Id = ''
    categoryStore.c3Arr = []
    categoryStore.c3Id = ''
    categoryStore.getC2()
}
//二级分类change事件
const handlerC2 = ()=>{
    categoryStore.c3Id = ''
    categoryStore.getC3()
}
</script>


<style scoped lang='scss'>

</style>